package com.itheima.controller;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {
    @Autowired
    private CheckGroupService checkGroupService;
    //新增
    @PostMapping("/add")
    public Result add(@RequestParam Integer[] checkitemIds, @RequestBody CheckGroup checkGroup) {
        checkGroupService.add(checkitemIds, checkGroup);
        return new Result(true, "新增检查组成功");
    }
    //根据id删除
    @GetMapping("/deleteById")
    public Result deleteById(Integer id) {
        int delete = checkGroupService.delete(id);
       return delete > 0 ? new Result(true, "删除检查组成功") : new Result(false, "删除检查组失败");
    }
    //根据套餐id查询套餐关联的检查组id
    @GetMapping("/findCheckGroupIdsBySetmealId")
    public Result findCheckGroupIdsBySetmealId(Integer setmealId) {
        return new Result(true, "查询检查组成功", checkGroupService.findCheckGroupIdsBySetmealId(setmealId));
    }
    // 分页查询
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return  checkGroupService.findPage(queryPageBean);
    }
     // 编辑
    @PostMapping("/edit")
    public Result edit(@RequestParam Integer[] checkitemIds, @RequestBody CheckGroup checkGroup){
        checkGroupService.edit(checkitemIds, checkGroup);
        return new Result(true,"编辑检查组成功");
    }
     //  查询所有
    @GetMapping("/findAll")
    public Result findAll() {
        return new Result(true, "查询检查组成功", checkGroupService.findAll());
    }
  //  根据id查询
    @GetMapping("/findById")
    public Result findById(Integer id) {
        return new Result(true, "查询检查组成功", checkGroupService.findById(id));
    }

}
